import java.util.*;

class ArraylistProg{
	public static void main(String[] args){
	
		//ArrayList()
		ArrayList<Object> li=new ArrayList<Object>();
		System.out.println("Initial size:"+ li.size());
		
		li.add(new Integer(1));
		li.add(new Integer(2));
		
		System.out.println("Size after adding:"+li.size());
		System.out.println("The elements are:"+li);
		
		li.add("S");
		li.add("A");
		li.add("I");
		li.add("B");
		
		System.out.println("Size after adding String objects:"+li.size());
		System.out.println("The elements are:"+li);
		
		li.remove(1);
		li.remove("B");
		
		System.out.println("The elements are:"+li);
		System.out.println("Iterator");
		Iterator itr=li.iterator();
		while(itr.hasNext())
		{
			Object element=itr.next();
			System.out.println(element);
			
		}
		
	
		System.out.println("After using Remove:"+li);
		
		//ArrayList(Collection c)
		
		ArrayList<Object> lic=new ArrayList<Object>(li);
		System.out.println("ArrayList with Collection li"+lic);
		lic.add("hii");
		System.out.println("ArrayList with Collection li"+lic);
		lic.add(3,li);
		System.out.println("ArrayList with Collection li"+lic);
		Iterator i=lic.iterator();
		Object ai[]=lic.toArray();
		System.out.println("ArrayList to array");
		for(int x=0;x<ai.length;x++)
		{
			System.out.println(" "+ai[x]);
		}
		//ArrayList(int capacity)
		ArrayList<Object> licap=new ArrayList<Object>(2);
		System.out.println("Initial size:"+licap.size());
		licap.add("hello");
		licap.add("namasthe");
		System.out.println("size after adding:"+licap.size());
		licap.add("vanakam");
		System.out.println("size after adding:"+licap.size());
		licap.remove("vanakam");
		System.out.println("size after removing:"+licap.size());
				
	}
	
}
